{% extends "base.html" %}

{% block content %}
<h2 class="mb-4">待办事项列表</h2>

<form method="POST" action="{{ url_for('todo.add_task') }}">
    {{ form.hidden_tag() }}
    <div class="row g-3">
        <div class="col-md-6">
            {{ form.title(class="form-control", placeholder="输入新任务") }}
        </div>
        <div class="col-md-3">
            {{ form.category(class="form-select") }}
        </div>
        <div class="col-md-3">
            {{ form.submit(class="btn btn-primary w-100") }}
        </div>
    </div>
</form>

<div class="mt-4">
    {% for task in tasks %}
    <div class="card mb-2">
        <div class="card-body d-flex justify-content-between align-items-center">
            <div>
                        <span class="badge bg-{{ 'success' if task.done else 'secondary' }} me-2">
                            {{ task.category }}
                        </span>
                <span class="{% if task.done %}text-decoration-line-through{% endif %}">
                            {{ task.title }}
                        </span>
            </div>
            <div>
                <a href="{{ url_for('todo.toggle_task', task_id=task.id) }}"
                   class="btn btn-sm btn-{{ 'outline-success' if task.done else 'success' }}">
                    {{ '✓' if task.done else '标记完成' }}
                </a>
                <a href="{{ url_for('todo.delete_task', task_id=task.id) }}"
                   class="btn btn-sm btn-danger ms-2">删除</a>
            </div>
        </div>
    </div>
    {% endfor %}
</div>
{% endblock %}